
'''
import pymysql as py 

con = py.connect(host='localhost',user="root",password="20040530Zzm**",db='python')
print('链接成功')
con.close()
'''



import pymysql as py


def insertfun(num,name,grade):
    try:
        con = py.connect(user="root", password="20040530Zzm**", db="python")
        print("连接成功")
        cr = con.cursor()
        sql="insert into stu values(%s,%s,%s)"
        cr.execute(sql,(num,name,grade))
        con.commit()
        cr.close()
        con.close()
    except Exception as err:
        print(err)



insertfun(5, "赵八", 60)

# def updatefun(grade,num):
#     try:
#         con = py.connect(user="root", password="20040530Zzm**", db="python")
#         print("连接成功")
#         cr = con.cursor()
#         update_sql="update stu set grade=%s where num =%s"
#         cr.execute(update_sql,(grade,num))
#         con.commit()
#         cr.close()
#         con.close()
#     except Exception as err:
#         print(err)
# updatefun(77,5)

# def deletefun(num):
#     try:
#         con = py.connect(user="root", password="20040530Zzm**", db="python")
#         print("连接成功")
#         cr = con.cursor()
#         delete_sql = "delete from stu where num=%s"

#         cr.execute(delete_sql,num)
#         con.commit()
#         cr.close()
#         con.close()
#     except Exception as err:
#         print(err)

# deletefun(5)



# def selectfun(num):
#     con=py.connect(user="root",password="123456",db="my1129")
#     cr=con.cursor(py.cursors.DictCursor)
#     sql ="select * from stu where num=%s"
#     cr.execute(sql,num)
#     result=cr.fetchall() #获取查询结果
#     print("num" + "  " + "name"+ "  " + "grade")
#     for row in result:
#         print(str(row["num"])+"  "+row["name"]+"  "+str(row["grade"]))
#     cr.close()
#     con.close()
# selectfun(1)















